package com.android.interfata;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

import com.android.menu.MenuAbout;
import com.android.menu.MenuContact;
import com.android.menu.MenuHelp;
import com.android.menu.MenuLegal;

public class InterfActivity extends TabActivity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
   {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Intent intent = getIntent();
        int actNr = intent.getIntExtra("activity", 0);
        
        Resources res = getResources(); // Resource object to get Drawables
		final TabHost tabHost = getTabHost(); // The activity TabHost

		Intent intent0 = new Intent(this, Search.class);
		tabHost.addTab(tabHost
				.newTabSpec("Search")
				.setIndicator("Search", res.getDrawable(R.drawable.search))
				.setContent(intent0));

		Intent intent1 = new Intent(this, Subscribe.class);
		tabHost.addTab(tabHost.newTabSpec("Subscription")
				.setIndicator("Subscription", res.getDrawable(R.drawable.subscribe))
				.setContent(intent1));

		Intent intent2 = new Intent(this, Bookmark.class);
		tabHost.addTab(tabHost.newTabSpec("Bookmark")
				.setIndicator("Bookmark", res.getDrawable(R.drawable.bookmark))
				.setContent(intent2));

		

		tabHost.setCurrentTab(actNr);

		tabHost.setBackgroundColor(Color.BLACK);
		tabHost.getTabWidget().setBackgroundColor(Color.BLACK);
		
		/****** Add animation *********/
		tabHost.setOnTabChangedListener(new OnTabChangeListener() 
		{
	        public void onTabChanged(String tabId) 
	        {
	        	View currentView = (View) tabHost.getCurrentView();
	        	currentView.setAnimation(inFromRightAnimation());
	        }
		});
    }
    
    
    public Animation inFromRightAnimation() 
    {

        Animation inFromRight = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, +0.5f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        inFromRight.setDuration(100);
        inFromRight.setInterpolator(new AccelerateInterpolator());
        return inFromRight;
    }

    public Animation outToLeftAnimation() {
        Animation outtoLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, -1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        outtoLeft.setDuration(1000);
        outtoLeft.setInterpolator(new AccelerateInterpolator());
        return outtoLeft;
    }
    
	/*     menu      */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
    	Intent intent;
        switch (item.getItemId()) 
        {
            case R.id.menu_about:     
            	intent = new Intent(getApplicationContext(), MenuAbout.class);
				startActivity(intent);
                break;
            case R.id.menu_help:     
            	intent = new Intent(getApplicationContext(), MenuHelp.class);
				startActivity(intent);
                break;
            case R.id.menu_legal: 
            	intent = new Intent(getApplicationContext(), MenuLegal.class);
				startActivity(intent);
            	break;
            case R.id.menu_contact:
            	intent = new Intent(getApplicationContext(), MenuContact.class);
				startActivity(intent);
            	break;
        }
        return true;
    }
	/*     end menu      */
}